<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .info_box {
        	background-color: #e62442;
        	margin-bottom: 6px;
        	padding-top: 48px;
        	padding-bottom: 15px;
        }
        .info_box .info .info_img {
        	width: 61px;
        	height: 61px;
        	border: 1px solid #fe9cab;
        	border-radius: 50%;
        	display: -webkit-box;
        	-webkit-box-align: center;
        	-webkit-box-pack: center;
        	margin: auto;
        }
        .info_box .info .info_img .img_box {
        	width: 55px;
        	height: 55px;
        	border-radius: 50%;
        	overflow: hidden;
        }
        .info_box .info .info_img .img_box img {
        	width: 100%;
        	height: 100%;
        	object-fit: cover;
        }
        .info_box .info .info_name {
        	font-size: 16px;
        	color: #fff;
        	text-align: center;
        	margin-top: 7px;
        	margin-bottom: 46px;
        }
        .price_box {
        	overflow: hidden;
        }
        .price_box .price_div {
        	width: 33.333333%;
        	float: left;
        	color: #fff;
        	text-align: center;
        	position: relative;
        }
        .price_box .price_div .price {
			font-size: 12px;
			margin-bottom: 6px;
        }
        .price_box .price_div .price span {
			font-size: 17px;
        }
        .price_box .price_div .price_p {
        	font-size: 12px;
        }
        .price_box .price_div .line {
        	width: 1px;
        	height: 20px;
        	background-color: #fff;
        	position: absolute;
        	right: 0;
        	top: 0;
        	bottom: 0;
        	margin: auto;
        }
        .main ul li .li_box {
            height: 50px;
            line-height: 50px;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            background-color: #fff;
            border-bottom: 1px solid #e8e8e8;
            padding-right: 15px;
        }
        .main ul li:last-child .li_box {
            border-bottom: none;
        }
        .main ul li .li_box .li_boxl {
            width: 35px;
            overflow: hidden;
            padding-right: 5px;
            box-sizing: border-box;
        }
        .main ul li .li_box .li_boxl img {
            width: 14px;
            display: block;
            float: right;
        }
        .main ul li:nth-child(1) .li_box .li_boxl img {
            width: 16px;
        }
        .main ul li:nth-child(2) .li_box .li_boxl img {
            width: 16px;
        }
        .main ul li:nth-child(3) .li_box .li_boxl img {
            width: 14px;
        }
        .main ul li:nth-child(4) .li_box .li_boxl img {
            width: 15px;
        }
        .main ul li:nth-child(5) .li_box .li_boxl img {
            width: 17px;
        }
        .main ul li:nth-child(6) .li_box .li_boxl img {
            width: 16px;
        }
        .main ul li .li_box .li_boxc {
            color: #333;
            font-size: 15px;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            padding-right: 5px;
        }
        .main ul li .li_box .li_boxr img {
            height: 12px;
            display: block;
        }
    </style>
</head>
<body>
	<div class="info_box">
		<div class="info">
			<div class="info_img">
				<div class="img_box">
					<img class="my_img" src="../image/my.png">
				</div>
			</div>
			<div class="info_name">&nbsp;</div>
		</div>
		<div class="price_box">
			<div class="price_div">
				<div class="price">RM<span class="date_income">&nbsp;&nbsp;&nbsp;&nbsp;</span></div>
				<div class="price_p">本日收入</div>
				<div class="line"></div>
			</div>
			<div class="price_div">
				<div class="price">RM<span class="week_income">&nbsp;&nbsp;&nbsp;&nbsp;</span></div>
				<div class="price_p">本周累计收入</div>
				<div class="line"></div>
			</div>
			<div class="price_div">
				<div class="price">RM<span class="month_income">&nbsp;&nbsp;&nbsp;&nbsp;</span></div>
				<div class="price_p">本月累计收入</div>
			</div>
		</div>
	</div>
    <div class="main">
        <ul>
            <li onclick="fnPersonData();" tapmode>
                <div class="li_box">
                    <div class="li_boxl">
                        <img src="../image/staff_my_icon1.png">
                    </div>
                    <div class="li_boxc">我的资料</div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                </div>
            </li>
            <li onclick="fnPersonComment();" tapmode>
                <div class="li_box">
                    <div class="li_boxl">
                        <img src="../image/comment.png">
                    </div>
                    <div class="li_boxc">我的评价</div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                </div>
            </li>
            <li onclick="fnPersonStatus();" tapmode>
                <div class="li_box">
                    <div class="li_boxl">
                        <img style="width: 16px;" src="../image/current_status.png">
                    </div>
                    <div class="li_boxc">当前状态</div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                </div>
            </li>
            <li>
                <div class="li_box" onclick="fnMyIncome();" tapmode>
                    <div class="li_boxl">
                        <img src="../image/staff_my_icon2.png">
                    </div>
                    <div class="li_boxc">我的收入</div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                </div>
            </li>
            <li onclick="fnPersonRecord();" tapmode>
                <div class="li_box">
                    <div class="li_boxl">
                        <img src="../image/staff_my_icon3.png">
                    </div>
                    <div class="li_boxc">提现记录</div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                </div>
            </li>
            <li tapmode onclick="fnJoinUs();">
                <div class="li_box">
                    <div class="li_boxl">
                        <img src="../image/staff_my_icon4.png">
                    </div>
                    <div class="li_boxc">申请成为骑手</div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                </div>
            </li>
            <li tapmode onclick="fnSet();">
                <div class="li_box">
                    <div class="li_boxl">
                        <img src="../image/my_icon5.png">
                    </div>
                    <div class="li_boxc">设置</div>
                    <div class="li_boxr">
                        <img src="../image/right.png">
                    </div>
                </div>
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function(){

        staffData = $api.getStorage('staff_data');
        getInitData();
        openLoading();
        analyIncome();
        // 下拉刷新
        api.setCustomRefreshHeaderInfo({
            bgColor: '#f8f8f8',
            loadAnimInterval:60,
            image: {
               pull: pullArr,
               load: loadArr
            }
        }, function(ret, err) {
            staffData = $api.getStorage('staff_data');
            getInitData();
            openLoading();
            analyIncome(1);
        });

        api.addEventListener({
            name: 'loginSuccess'
        }, function(ret, err){
            if( ret ){
                staffData = $api.getStorage('staff_data');
                getInitData();
                openLoading();
                analyIncome();
            }
        });

        api.addEventListener({
            name: 'changeStaffHead'
        }, function(ret, err){
            if( ret ){
                $(".my_img").attr('src',formatHeadImg(ret.value.path));
            }
        });

        api.addEventListener({
            name: 'updateMyIncome'
        }, function(ret, err){
            if( ret ){
                // 更新一下本日，本周，本月收入
                analyIncome();
            }
        });

        api.addEventListener({
            name: 'toOpenStatusWin'
        }, function(ret, err){
            if( ret ){
                var staffData = $api.getStorage('staff_data');
                api.openWin({
                    name: 'personal_status',
                    url: './personal_status.html',
                    pageParam:{
                        is_online:staffData.is_online,
                        totalTime: ret.value.totalTime,
                    }
                });
            }
        });

    };

    function fnPersonComment () {
        api.openWin({
            name: 'comment',
            url: './comment.html',
        });
    };

    function fnMyIncome () {
        api.openWin({
            name: 'income',
            url: './income.html',
        });
    };

    function analyIncome (t) {
        if (staffData) {
            api.ajax({
                url: rootPath + '/api/staff/get_each_income',
                method: 'get',
                cache: true,
                data: {
                    values: { 
                        staff_id: staffData.id,
                        staff_token: staffData.token,
                    },
                }
            }, function(ret, err) {
                if(ret.status == 200){
                    if(ret.data.date_income){
                        $(".date_income").html(ret.data.date_income);
                    }
                    if(ret.data.week_income){
                        $(".week_income").html(ret.data.week_income);
                    }
                    if(ret.data.month_income){
                        $(".month_income").html(ret.data.month_income);
                    }
                }
                closeLoading();
            });
        }
        if(t == 1){
            api.refreshHeaderLoadDone();
        }
    }

    function getInitData () {
        // alert(formatHeadImg(staffData.img));
        if(staffData){
            $(".my_img").attr('src',formatHeadImg(staffData.img));
        }
        if(staffData && staffData.username){
            $(".info_name").html(staffData.username);
        }
    };

    function fnPersonData() {
        api.openWin({
            name: 'personal_data',
            url: './personal_data.html',
        });
    }

    function fnPersonStatus () {
        /*// 先把缓存清了
        $api.setStorage('newest_time',-1);
        // 再发通知去更新缓存
        var newestTime = $api.getStorage('newest_time');*/
        api.sendEvent({
            name: 'updateNewestTime',
        });
        return;
        var newestTime = $api.getStorage('newest_time');
        if(newestTime >= 0){
            var staffData = $api.getStorage('staff_data');
            api.openWin({
                name: 'personal_status',
                url: './personal_status.html',
                pageParam:{
                    is_online:staffData.is_online
                }
            });
        }
    };

    function fnPersonRecord() {
        api.openWin({
            name: 'present_record',
            url: './present_record.html',
        });
    }

    // 加入我们
    function fnJoinUs() {
        api.openWin({
            name: 'join_us',
            url: './join_us.html'
        });
    }

    // 设置
    function fnSet() {
        api.openWin({
            name: 'set',
            url: './set.html'
        });
    }


</script>
</html>